package cn.edu.shengda;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CoffeeFrame extends JFrame implements ActionListener {
    CoffeeFrame(){
        init();
        this.setTitle("咖啡");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setBounds(0,0,800,600);
        this.setVisible(true);
    }
    public void init(){
        radioButtonCoffe=new JRadioButton("咖啡");
        radioButtonMilkTea=new JRadioButton("奶茶");
        checkBoxMocha=new JCheckBox("摩卡 10");
        checkBoxPearl=new JCheckBox("珍珠 15");
        checkBoxWhip=new JCheckBox("奶泡 10");
        checkBoxChocolate=new JCheckBox("巧克力 20");
        labelPrice=new JLabel("价格：");
        radioButtonCoffe.addActionListener(this);
        radioButtonMilkTea.addActionListener(this);
        checkBoxMocha.addActionListener(this);
        checkBoxPearl.addActionListener(this);
        checkBoxWhip.addActionListener(this);
        checkBoxChocolate.addActionListener(this);
        add(radioButtonCoffe);
        add(radioButtonMilkTea);
        add(checkBoxMocha);
        add(checkBoxPearl);
        add(checkBoxWhip);
        add(checkBoxChocolate);
        add(labelPrice);
        group=new ButtonGroup();
        group.add(radioButtonCoffe);
        group.add(radioButtonMilkTea);
    }
    JRadioButton radioButtonCoffe;
    JRadioButton radioButtonMilkTea;
    JCheckBox checkBoxMocha;
    JCheckBox checkBoxPearl;
    JCheckBox checkBoxWhip;
    JCheckBox checkBoxChocolate;
    JLabel labelPrice;
    ButtonGroup group;
    Beverage beverage;
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource().equals(radioButtonCoffe)){
            System.out.println("咖啡被选中");
            beverage=new DarkRoast();
            System.out.println(beverage.getDescription()+"$"+
                    beverage.cost());
        }
        if(e.getSource().equals(radioButtonMilkTea)){
            System.out.println("奶茶被选中");
            beverage=new Espresso();
            System.out.println(beverage.getDescription()+"$"+
                    beverage.cost());
        }
        if(e.getSource().equals(checkBoxMocha)){
            System.out.println("摩卡被选中");
            beverage=new Mocha(beverage);
            System.out.println(beverage.getDescription()+"$"+
                    beverage.cost());
        }
        if(e.getSource().equals(checkBoxPearl)){
            System.out.println("珍珠被选中");

        }
        if(e.getSource().equals(checkBoxWhip)){
            System.out.println("奶泡被选中");
            beverage=new Whip(beverage);
            System.out.println(beverage.getDescription()+"$"+
                    beverage.cost());
        }
        if(e.getSource().equals(checkBoxChocolate)){
            System.out.println("巧克力被选中");
        }
    }
    public static void main(String[] args){
        CoffeeFrame coffeeFrame =new CoffeeFrame();
        coffeeFrame.setLayout(new FlowLayout());
    }
}
